package cn.bonoon.kernel.web.handlers.loader;

import java.lang.reflect.AnnotatedElement;

import cn.bonoon.handler.impl.StandardAutoManager;
import cn.bonoon.kernel.events.ReadEvent;
import cn.bonoon.kernel.support.models.Page;
import cn.bonoon.kernel.support.searcher.Finder;
import cn.bonoon.kernel.support.services.ISearchable;
import cn.bonoon.kernel.web.annotations.AutoDataLoader;

/**
 * <pre>
 * 用于datagrid的分页加载数据和不分页加载数据
 * 是否分页加载数据，框架会自动根据查询条件对象的类型进行判断
 * </pre>
 * @author jackson
 *
 * @param <E>
 */
public class ItemLoaderHandler extends AbstractSearchableLoaderHandler {
	
	public ItemLoaderHandler(ISearchable searchable, Class<?> resultClass, Class<?> queryClass, AnnotatedElement aEle) throws Exception {
		super(searchable, resultClass, queryClass, aEle);
//		sup
//		super(searchable, resultClass, new StandardQueryParameterBuilder(queryClass, searchable.getSearcher()));
////		EntityDescriptor ed = searcher.getSearcher().getEntityDescriptor();
//		FinderFilter ff = aEle.getAnnotation(FinderFilter.class);
//		if(null == ff){
//			defaultFilter(aEle);
//		}else{
//			setFilter(ff.value(), aEle);
//		}
	}

	public ItemLoaderHandler(StandardAutoManager manager, Class<?> resultClass, Class<?> queryClass, AutoDataLoader loader) throws Exception{
		super(manager, resultClass, queryClass, loader);
	}

	@Override
	protected Page __parseResult(Finder finder, ReadEvent event) throws Exception {
		return finder.getPage();
	}
	
//	@Override
//	public Page execute(ReadEvent event) throws Exception {
////		ISearcher ser = searchable.getSearcher();
//		StandardFinder finder = searcher.finder(entityManager, event, resultClass);
//		finder.combineExpression(expressionParser);
//		
//		Object con = event.getSource();
//		if(null != con){
//			QueryConverter qc = searcher.getQueryConverter(con.getClass());
//			qc.query(finder.getAsmParser(), con);
//		}
//		
//		finder.parseExpression(event);
//		
//		filter.filter(finder, event);
//		return parseQuery(finder, event);
//	}
	
//	protected Page parseQuery(Finder finder, ReadEvent event){
//		return finder.getPage();
//	}
}
